Expand description
This crate provides the tools for positioning and rendering text in Bevy.
§Font
Fonts contain information for drawing glyphs, which are shapes that typically represent a single character, but in some cases part of a “character” (grapheme clusters) or more than one character (ligatures).
A font face is part of a font family, and is distinguished by its style (e.g. italic), its weight (e.g. bold) and its stretch (e.g. condensed).
In Bevy, Font
s are loaded by the FontLoader
as assets.
§TextPipeline
The TextPipeline
resource does all of the heavy lifting for rendering text.
UI Text
is first measured by creating a TextMeasureInfo
in TextPipeline::create_text_measure
,
which is called by the measure_text_system
system of bevy_ui
.
Note that text measurement is only relevant in a UI context.
With the actual text bounds defined, the bevy_ui::widget::text::text_system
system (in a UI context)
or text2d::update_text2d_layout
system (in a 2d world space context)
passes it into TextPipeline::queue_text
, which:
- updates a
Buffer
from theTextSpan
s, generating newFontAtlasSet
s if necessary. - iterates over each glyph in the
Buffer
to create aPositionedGlyph
, retrieving glyphs from the cache, or rasterizing to aFontAtlas
if necessary. PositionedGlyph
s are stored in aTextLayoutInfo
, which contains all the information that downstream systems need for rendering.
Re-exports§
pub use cosmic_text;
Modules§
- The text prelude.
Structs§
- Computed information for a text block.
- Wrapper for
cosmic_text::Buffer
- A wrapper resource around a
cosmic_text::FontSystem
- An
Asset
that contains the data for a loaded font, if loaded as an asset. - Rasterized glyphs are cached, stored in, and retrieved from, a
FontAtlas
. - Identifies a font size and smoothing method in a
FontAtlasSet
. - A map of font sizes to their corresponding
FontAtlas
es, for a given font face. - A map of font faces to their corresponding
FontAtlasSet
s. - Specifies the weight of glyphs in the font, their degree of blackness or stroke thickness.
- Information about a glyph in an atlas.
- The location of a glyph in an atlas, and how it should be positioned when placed.
- A glyph of a font, typically representing a single character, positioned in screen space.
- A wrapper resource around a
cosmic_text::SwashCache
- The top-level 2D text component.
- Text2d
Bundle Deprecated Text2dBundle
was removed in favor of required components. The core component is nowText2d
which can contain a single text segment. Indexed access to segments can be done with the newText2dReader
andText2dWriter
system params. Additional segments can be added through children withTextSpan
. Text configuration can be done withTextLayout
,TextFont
andTextColor
, while sprite-related configuration usesTextBounds
andAnchor
components. - The maximum width and height of text. The text will wrap according to the specified size.
- The color of the text for this section.
- A sub-entity of a
ComputedTextBlock
. TextFont
determines the style of a text span within aComputedTextBlock
, specifically the font face, the font size, and the color.- Component with text format settings for a block of text.
- Render information for a corresponding text block.
- Size information for a corresponding
ComputedTextBlock
component. - Adds text rendering support to an app.
- System parameter for reading text spans in a text block.
- Iterator returned by
TextReader::iter
. - System parameter for reading and writing text spans in a text block.
- System set in
PostUpdate
where all 2d text update systems are executed.
Enums§
- An owned version of
Family
- Possible errors that can be produced by
FontLoader
- Determines which antialiasing method to use when rendering text. By default, text is rendered with grayscale antialiasing, but this can be changed to achieve a pixelated look.
- A face width.
- Allows italic or oblique faces to be selected.
- Describes the horizontal alignment of multiple lines of text relative to each other.
- Determines how lines will be broken when preventing text from running out of bounds.
- Errors related to the textsystem
- Text is rendered for two different view projections; 2-dimensional text (
Text2d
) is rendered in “world space” with aBottomToTop
Y-axis, while UI is rendered with aTopToBottom
Y-axis. This matters for text because the glyph positioning is different in either layout. ForTopToBottom
, 0 is the top of the text, while forBottomToTop
0 is the bottom.
Constants§
- The raw data for the default font used by
bevy_text
Traits§
- Helper trait for the root text component in a text block.
- Helper trait for using the
TextReader
andTextWriter
system params. - Helper trait for the text span components in a text block.
Functions§
- System calculating and inserting an
Aabb
component to entities with someTextLayoutInfo
andAnchor
components, and without aNoFrustumCulling
component. - System that detects changes to text blocks and sets
ComputedTextBlock::should_rerender
. - This system extracts the sprites from the 2D text components and adds them to the “render world”.
- A system that cleans up
FontAtlasSet
s for removedFont
s - Scales
value
byfactor
. - Updates the layout and size information whenever the text or style is changed. This information is computed by the
TextPipeline
on insertion, then stored.
Type Aliases§
- 2d alias for
TextReader
. - 2d alias for
TextWriter
.